import request from '@/utils/request'
// import qs from 'qs'
// 获取所有用户信息 
export const userGetList = ({ page, pageSize }) => {
  return request({
    url: '/admin/user/list',
    method: 'get',
    params: {
      page,
      pageSize
    }
  })
}
//验证用户名是否可用
export const usernameCheck = (username) => {
  return request.get(`/admin/user/username/${username}`)
}
// 根据部门岗位信息获取用户信息
export const userGetListBySearch = ({ username, name, status, deptId, job, roleId, page, pageSize }) => {
  return request({
    url: '/admin/user/searchlist',
    method: 'post',
    data: {
      username: username,
      name: name,
      status: status,
      deptId: deptId,
      job: job,
      roleId: roleId,
      page: page,
      pageSize: pageSize
    }
  })
}
// 获取层级形式的部门列表
export const deptCasList = () => {
  return request({
    url: '/admin/dept/casList',
    method: 'get'
  })
}

// 获取角色列表
export const roleGetList = () => {
  return request({
    url: '/admin/role/list',
    method: 'get'
  })
}
// 新增用户
export const userAdd = (userInfo) => {
  return request({
    url: '/admin/user/add',
    method: 'post',
    data: userInfo
  })
}
// 删除用户
export const userDel = (id) => {
  return request({
    url: '/admin/user/del',
    method: 'delete',
    params: {
      id,
    }
  })
}
// 批量修改启用状态(启用)
export function userBatchStatusUpdate({ userInfoList, statusTo }) {
  return request({
    url: '/admin/user/statusbatch',
    method: 'put',
    data: { userInfoList, statusTo }
  })
}

export function userStatusUpdate(id, statusTo) {
  return request({
    url: '/admin/user/status',
    method: 'put',
    data: { id: id, status: statusTo }
  })
}
// 修改用户信息
export const userUpdate = (userInfo) => {
  return request({
    url: '/admin/user/update',
    method: 'put',
    data: userInfo
  })
}

// 架构页面
// 根据部门id获取岗位信息(user页面没用到)
export const jobGetListByDeptId = (deptId) => {
  return request({
    url: '/admin/structure/joblist',
    method: 'get',
    params: {
      deptId,
    }
  })
}
// 修改架构名称
export const editDeptName = (deptId, deptName) => {
  return request({
    url: '/admin/structure/editDeptName',
    method: 'put',
    params: {
      deptId,
      deptName
    }
  })
}
// 新增架构
export const addDept = (parentId, deptName) => {
  return request({
    url: '/admin/structure/addDept',
    method: 'put',
    params: {
      parentId,
      deptName
    }
  })
}
//删除架构
export const delDept = (id) => {
  return request({
    url: `/admin/structure/delDept/${id}`,
    method: 'delete'
  })
}
//新增岗位
export const addJob = (data) => {
  return request({
    url: '/admin/structure/addJob',
    method: 'put',
    data: data
  })
}
// 删除岗位
export const delJobs = (ids) => {
  return request({
    url: 'admin/structure/delJobs',
    method: 'delete',
    data: ids
  })
}

// 角色权限管理
export const getMenuList = () => {
  return request({
    url: '/admin/permission/menulist',
    method: 'get',
  })
}

export const getRoleMenuID = (id) => {
  return request({
    url: '/admin/permission/roleMenuID',
    method: 'get',
    params: {
      id
    }
  })
}
// 设置权限
export const setRoleMenuID = (roleId, ids) => {
  return request({
    url: '/admin/permission/setroleMenu',
    method: 'post',
    data: {
      roleId,
      ids
    }
  })
}

// 删除角色
export const roleDel = (id) => {
  return request.delete(`/admin/permission/delrole/${id}`)
}

//新增角色
export const roleAdd = ({ roleName, roleCode, description }) => {
  return request({
    url: '/admin/permission/addRole',
    method: 'post',
    data: {
      roleName, roleCode, description
    }
  })
}

// 获取仓库列表
export const getWhlist = (type) => {
  return request({
    url: 'admin/warehouse/whlist',
    method: 'get',
    params: { type }
  })
}

// 通过部门ID搜索用户
export const getUserListByDeptId = (deptId) => {
  return request({
    url: 'admin/warehouse/dept/' + `${deptId}`,
    method: 'get'
  })
}
//修改仓库管理员
export const setWhAdmins = (whId, data) => {
  return request({
    url: 'admin/warehouse/whadmins/' + `${whId}`,
    method: 'post',
    data: data
  })
}

// 通过仓库ID查询管理员
export const getUserListByWhId = (whId) => {
  return request({
    url: '/admin/warehouse/wh/' + `${whId}`,
    method: 'get'
  })
}

// 通过仓库ID删除仓库
export const delInventory = (whId) => {
  return request({
    url: 'admin/warehouse/wh',
    method: 'delete',
    params: { whId, }
  })
}
// 查询仓库类型列表
export const getWhType = () => {
  return request({
    url: 'admin/warehouse/whtype',
    method: 'get'
  })
}

//新增或修改仓库基本信息
export const updateWh = (whInfo) => {
  return request({
    url: 'admin/warehouse/updateWh',
    method: 'post',
    data: whInfo
  })
}

// 新增仓库类型
export const addWhType = (data) => {
  return request({
    url: 'admin/warehouse/type',
    method: 'post',
    data: data,
  })
}

// 查询供应商信息
export const getVendorList = () => {
  return request({
    url: 'admin/vendor/list',
    method: 'get'
  })
}
// 修改供应商信息
export const editVendor = (data) => {
  return request({
    url: 'admin/vendor/edit',
    method: 'post',
    data: data,
  })
}

// 删除供应商信息
export const delVendor = (id) => {
  return request({
    url: 'admin/vendor/' + `${id}`,
    method: 'delete',
  })
}
// 获取供应商状态
// export const getstatus = () => {
//   return request({
//     url: 'admin/vendor/status',
//     method: 'get'
//   })
// }

// 新增供应商
export const addVendor = (data) => {
  return request({
    url: 'admin/vendor/add',
    method: 'post',
    data: data,
  })
}